// pages/share/share.js
const app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    banner: null,
    dataFinish: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (app.globalData.userId) {
      wx.showLoading({
        title: '加载中',
      })
      wx.request({
        url: app.baseURL + 'Share&a=index',
        success: res => {
          const data = res.data;
          data.ad.content = "https://rybc.0791jr.com/data/attachment/advert/" + data.ad.content;
          //调用wxParse解析html文本
          WxParse.wxParse('shareRules', 'html', data.instruction.info, this, 0);
          this.setData({
            banner: data.ad.content,
            dataFinish: true
          });
          wx.hideLoading();
        }
      })
    }else{
      app.toLogin();
    }
  },

  // 转发
  onShareAppMessage() {
    const userId = app.globalData.userId;
    return {
      title: '嘉瑞新零售',
      path: '/page/index/index?other_user_id=' + userId,
      success(res) {
        // 转发成功
        console.log('成功');
      },
      fail(err) {
        // 转发失败
        console.log('失败');        
      }
    }
  }
})